<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
>
<head>
    <title>WebSSH</title>

    <link th:href="@{/webssh/xterm.css}" rel="stylesheet" type="text/css"/>

    <script th:src="@{/webssh/webssh.js}" type="text/javascript"></script>
    <script th:src="@{/webssh/xterm.js}" type="text/javascript"></script>
</head>
<body>
<div id="terminal" style="width: 100%;height: 100%"></div>
<script>
    let ctxPath = '[[${#servletContext.contextPath}]]';
    let serverId = '[[${serverId}]]';
    openTerminal({
        operate: 'connect',
        serverId: serverId,//ssh的id
        // host: '192.168.1.180',//IP
        // port: '22',//端口号
        username: 'root',//用户名
        // password: 'JieYiS@ft'//密码
    });

    function openTerminal(options) {
        let client = new WSSHClient();
        let term = new Terminal({
            cols: 97,
            rows: 37,
            cursorBlink: true, // 光标闪烁
            cursorStyle: "block", // 光标样式  null | 'block' | 'underline' | 'bar'
            scrollback: 800, //回滚
            tabStopWidth: 8, //制表宽度
            screenKeys: true
        });

        term.on('data', function (data) {
            //键盘输入时的回调函数
            client.sendClientData(data);
        });
        term.open(document.getElementById('terminal'));
        //在页面上显示连接中...
        term.write('Connecting ' + serverId + '...');
        //执行连接操作
        client.connect(ctxPath, {
            onError: function (error) {
                //连接失败回调
                term.write('Error: ' + error + '\r\n');
            },
            onConnect: function () {
                //连接成功回调
                client.sendInitData(options);
            },
            onClose: function () {
                //连接关闭回调
                term.write("\rconnection closed");
            },
            onData: function (data) {
                //收到数据时回调
                term.write(data);
            }
        });
    }
</script>
</body>
</html>